home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3806 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: centre.univ-orleans.fr!desiree!emmguyot
  2. From: emmguyot@desiree.univ-orleans.fr (Emmanuel GUYOT)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to test a random generator ?
  5. Date: 31 Jan 1996 09:57:34 GMT
  6. Organization: CITU - Universite d'Orleans - FRANCE
  7. Message-ID: <4eneee$86r@centre.univ-orleans.fr>
  8. References: <4e2q7g$oe@centre.univ-orleans.fr> <4e933p$t25@longwood.cs.ucf.edu> <9603010.14743@mulga.cs.mu.OZ.AU>
  9. NNTP-Posting-Host: desiree.cnrs-orleans.fr
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Stephen Baillie (baillie@munta.cs.mu.OZ.AU) wrote:
  13.  
  14. : There are various statistical tests you can use to determine if a
  15. : random number generator exhibits certain properties of truly
  16. : random sequences.  The most common/appropriate/applicable is
  17. : probably the chi squared test.  Basically, you take n random
  18. : numbers from the range a - b, then take the sum of the squares
  19. : of the differences between the actual occurances of each number
  20. : and the expected or average number, take the square root, and
  21. : the result should be roughly b-a.  Too close to zero and it's
  22. : not random enough; too large and it shows too much bias towards
  23. : particular numbers.  An example:
  24.  
  25. :     average = (double) iterations / (double) range;
  26. :     for (chi2 = 0, i = 0; i < range; i++)
  27. :         chi2 += (counts[i] - average) * (counts[i] - average);
  28.  
  29. :     /* Report the chi value, and a very rough assessment of the RNG */
  30. :     printf("Chi value = %f ", sqrt(chi2));
  31. :     if (sqrt(chi2) < range / 2)
  32. :         printf("(not random enough)\n");
  33. :     else if (sqrt(chi2) > range * 2)
  34. :         printf("(too biased)\n");
  35. :     else
  36. :         printf("(not bad)\n");
  37.  
  38.  
  39. I'm a bit surprise by this because if you take a low number of iterations,
  40. I have the 'not bad' comment whereas if I use a high number of iterations
  41. I have the 'too biased' comment.
  42.  
  43. Shouldn't the chi2 variable be average or something like that to take into
  44. account the number of iterations ?
  45.  
  46. E.G.
  47.  
  48. ------------------------------------------------------------------------------
  49. ---------------------------->>>> Emmanuel Guyot <<<<--------------------------
  50. LPCE-CNRS                              | 
  51. 3A avenue de la Recherche Scientifique | Phone     : 33 38 51 78 25
  52. 45071 Orleans Cedex 2                  | Fax       : 33 38 63 12 34
  53. France                                 | EMail     : emmguyot@cnrs-orleans.fr
  54. ------------------------------------------------------------------------------
  55. Home Page : http://desiree.cnrs-orleans.fr/cgi-bin/cpt_html?index
  56. ------------------------------------------------------------------------------
  57.